/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package sales.managedbean;

import company.entity.Company;
import java.io.IOException;
import java.io.Serializable;
import java.util.Collection;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
import javax.faces.context.FacesContext;
import javax.faces.event.PhaseEvent;
import sales.entity.LineItem;
import sales.entity.SalesOrderEntity;

/**
 *
 * @author xhx
 */
@ManagedBean
@ViewScoped
public class DisplaySalesOrderManagedBean implements Serializable{
   private SalesOrderEntity salesOrder;
   private Company customer;
   private Collection<LineItem> lineItemList;
    /** Creates a new instance of DisplaySalesOrderManagedBean */
    public DisplaySalesOrderManagedBean() {
 
    }
    
    public void initView(PhaseEvent event) {
        if (getSalesOrder() == null) { 
            salesOrder = (SalesOrderEntity) FacesContext.getCurrentInstance().getExternalContext().getFlash().get("newSalesOrder");
        }
            setLineItemList(salesOrder.getSalesOrderLineItems());
            setCustomer(salesOrder.getCustomer());
    }
   
     public void reDirect() throws IOException{
        FacesContext.getCurrentInstance().getExternalContext().redirect("viewAllSalesOrder.xhtml");
    }
    public SalesOrderEntity getSalesOrder() {
        return salesOrder;
    }

    public void setSalesOrder(SalesOrderEntity salesOrder) {
        this.salesOrder = salesOrder;
    }

    public Company getCustomer() {
        return customer;
    }

    public void setCustomer(Company customer) {
        this.customer = customer;
    }

    public Collection<LineItem> getLineItemList() {
        return lineItemList;
    }

    public void setLineItemList(Collection<LineItem> lineItemList) {
        this.lineItemList = lineItemList;
    }
}
